using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using EY;

public class UIHatLotteryItem : UIBaseItem
{
    [SerializeField] Button m_hatBtn;                   // 帽子抽奖按钮
    [SerializeField] GameObject m_rewardParent;         // 奖励父节点
    [SerializeField] Image m_rewardIcon;                // 奖励图片
    [SerializeField] GameObject m_rewardLight;          // 中奖特效
    [SerializeField] Text m_rewardCount;                // 奖励数量

    public bool isClicked;                              // 是否被点击

    private void Start()
    {
        m_hatBtn.onClick.AddListener(GetLotteryItemBtnClicked);
    }

    /// <summary>
    /// 点击抽奖按钮
    /// </summary>
    private void GetLotteryItemBtnClicked()
    {
        Debug.Log($"点击抽奖按钮 UIHatLotteryItem");
        isClicked = true;
        // TODO: 根据概率计算是否中奖, 计算奖励内容
        EventManager.Instance.TriggerEvent(new GameEvent(EEventType.Logic_HatLottery_ClickHat));
        // TODO: 播放帽子消失动画, 显示当前所选奖励内容

        // TODO: 如果有奖励, 延迟一定时间后播放其他帽子消失动画, 以及展示所有奖励内容
    }

    /// <summary>
    /// 展示奖励内容
    /// </summary>
    public void ShowReward(int[] reward)
    {
        if (reward == null)
        {
            m_rewardIcon.sprite = null;
            m_rewardCount.text = string.Empty;
            m_rewardLight.SetActive(false);
        }
        else
        {
            int id = reward[0];
            int count = reward[1];
            ITEMS_DATA item = DICT_ITEMS.Para[id];
            m_rewardIcon.sprite = AssetsHelper.GetSprite(item.ATLAS, item.ICON);
            m_rewardCount.text = $"×{count}";
            m_rewardLight.SetActive(true);
        }

        m_rewardParent.SetActive(true);
        // TODO: 播放帽子消失动画
        m_hatBtn.gameObject.SetActive(false);
    }

    /// <summary>
    /// 隐藏奖励内容
    /// </summary>
    public void HideReward()
    {
        m_rewardParent.SetActive(false);
        m_hatBtn.gameObject.SetActive(true);
    }
}
